import React, { useState, useEffect } from 'react';
import { View } from 'react-native';
import { Toast } from '@ant-design/react-native';
import AddButton from '../../components/common/AddButton';
import { selectPlan } from '../../comconfig/sqlfun';
import PlanView from '../../components/PlanView/index';

const TaskPlan = ({ navigation }) => {
    const [planList, setPlanList] = useState([]);
    const getPlanList = async () => {
        try {
            const list = await selectPlan(0, '');
            const arr = [];
            for (let i = 0; i < list.length; i += 1) {
                arr.push(JSON.parse(list[i]));
            }
            setPlanList(arr);
        } catch (error) {
            Toast.info('获取数据失败', 1, undefined, false);
        }
    };
    useEffect(() => {
        getPlanList();
    }, []);
    return (
        <View>
            <PlanView navigation={navigation} planList={planList} getPlanList={getPlanList} />
            <AddButton
                navigation={navigation}
                funList={{ getPlanList }}
                action="添加计划"
            />
        </View>
    );
};

export default TaskPlan;
